<template>
  <div :style="backgroundDiv">


  <div class="login_top_wrapper">
    <div class="login_top_inner" style="background-color: #2c3e50;width: 100%;">
      <div class="text_wrapper" style="color: #ffd04b;font-weight: bold;font-size: 30px;line-height: 60px;">
        ★特征英语★
      </div>
    </div>
  </div>
  <div class="login_wrapper" style="height: 525px;">
    <div class="login_inner" style="margin: 0 auto;width: 400px;height: 300px;margin-top: 50px;
    border: 0px solid red;display: flex;flex-direction: column;
    box-shadow: 0px 0px 12px #ffd04b; ">
      <div class="top_text_wrapper" style="">
        <div class="top_text_inner" style="font-size: 30px;font-weight: bold;
        border: 0px solid red;
        color: #ffd04b;margin: 20px auto;">
          登&nbsp&nbsp录
        </div>
      </div>
      <div class="user_pass_wrapper">
        <div class="username_wrapper ">
          <div class="username_inner">
            <div class="input_left_text">用户名：</div>
            <el-input placeholder="请输入内容" v-model="username" clearable ></el-input>
          </div>
        </div>
        <div class="password_wrapper " style="margin-top: 30px;">
          <div class="password_inner">
            <div class="input_left_text">密码：</div>
            <el-input placeholder="请输入密码" v-model="password" show-password></el-input>
          </div>
        </div>
      </div>
      <div class="login_btn_wrapper" style="margin: 20px auto">
        <el-button type="warning" style="min-width: 250px;" @click="login"><span>登&nbsp&nbsp&nbsp&nbsp&nbsp录</span></el-button>
      </div>

    </div>
  </div>


  </div>
</template>

<script>
  import {postRequest} from "../utils/api";

  export default {
      name: "login",
      data(){
        return {
          username: '李白',
          password: '111',
          backgroundDiv: {
            backgroundImage:'url(' + require('../assets/back.jpg') + ')',
            backgroundRepeat:'no-repeat',
            backgroundSize:'100% 100%'
          }
        }
      },
      methods: {
        login(){
          console.debug("enter login method")
          let param = {
            username: this.username,
            password: this.password,
            token: this.username
          }
          const loading = this.$loading({lock: true, text: 'Loading', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)'});
          postRequest('/user_consumer/dologin', param).then(res=>{
            console.debug("dologin return info:"+JSON.stringify(res.data))
            setTimeout(() => {loading.close();}, 1000);
            if(res.data.code == 1){
              console.debug("登录成功 token:"+res.data.t)
              window.localStorage.setItem("token", res.data.t)
              this.$message({showClose: true, message: res.data.msg, type: 'success'});
              this.$router.push('/index')
            }else {
              this.$message({showClose: true, message: res.data.msg, type: 'error'});
            }
          }).catch(err=>{
            console.debug("login fail info:"+JSON.stringify(err))
            setTimeout(() => {loading.close();}, 1000);
            this.$message({showClose: true, message: '登录失败，服务器异常', type: 'error'});
          })
        }
      }
    }
</script>

<style scoped>
  .input_left_text{

  }
  .user_pass_wrapper{border: 0px solid red;max-width: 300px;margin: 0 auto; padding-right: 20px;}
  .user_pass_wrapper div{
    display: flex;flex-direction: row;
  }
  .user_pass_wrapper .input_left_text{
    min-width: 80px;display: flex;flex-direction: row-reverse;line-height: 40px;
    color: #ffd04b;font-weight: bold;
  }
  el-input{
    width: 100px;
  }
</style>
